import { Command } from "../class/Command";
import { TakeCardTooFastError } from "../class/errors";
import { CardFactory } from "../factory/CardFactory";

/** 拿牌间隔 */
const Time = 5E3;

export class TakeCard extends Command {
    static commandName = "拿牌/签到/取牌";
    static test(commandName: string): boolean {
        return ['拿牌', '签到', '取牌'].indexOf(commandName) > -1;
    }
    invoke() {
        const role = this.game.getRole(this.context.getId())

        if (role.getAttrbuite("takeCard", 0) + Time < Date.now()) {
            const CardSubCLass = CardFactory.getByName(); // 随机获取一张牌
            const card = new CardSubCLass(this.masterRole);
            role.setAttrbuite("takeCard", Date.now())
            role.addCard(card);
        } else {
            throw new TakeCardTooFastError()
        }
    }
}